package com.rjkj.medicalwaste.network.response

class BaseResponse<T> {
    val data: T? = null
    val code: Int? = null
    val message: String? = null
    var exception: Exception? = null
}

inline fun <T> BaseResponse<T>.next(bloc: BaseResponse<T>.() -> Unit): BaseResponse<T> {
    return if (exception == null) {//没有异常，则把正确结果bloc出去
        bloc()
        this
    } else {//出现异常（网络/服务器/自定义异常）执行这里 不用bloc
        this
    }

}

fun <T> BaseResponse<T>.deal(): T? {
    return if (exception == null) {
        if (this.code == 200) {
            this.data
        } else {
            null
        }
    } else {
        null
    }

}

inline fun <T> BaseResponse<T>.catchException(bloc: Exception.() -> Unit) {
    if (exception != null) {
        bloc(exception!!)
    }
}